#include <stdio.h>
#include <unistd.h>
#include "threadpool.h"

/*测试*/ 
#if 1
/* 线程池中的线程，模拟处理业务 */
void *process(void *arg)
{
    printf("thread id :0x%x working on task %d\n ",(unsigned int)pthread_self(),*(int *)arg);
    sleep(1);
    printf("task %d is end\n",*(int *)arg);

    return NULL;
}
int main(void)
{
    
	/*创建线程池，池里最小3个线程，最大100，队列最大100*/
    threadpool_t *thp = threadpool_create(3,100,100);
    printf("pool inited");

    //int *num = (int *)malloc(sizeof(int)*20);
    int num[20], i;
    for (i = 0; i < 20; i++) {
        num[i]=i;
        printf("add task %d\n",i);
        threadpool_add(thp, process, (void*)&num[i]);     /* 向线程池中添加任务 */
    }
    sleep(10);                                          /* 等子线程完成任务 */
    threadpool_destroy(thp);

    return 0;
}

#endif
